#ifndef NP_DAOCHAPTER_H
#define NP_DAOCHAPTER_H

#include "Daobase.h"
#include <string>
#include <mysql/mysql.h>
#include <config/Structures.h>

class DaoChapter : public Daobase
{
public:
  DaoChapter() : Daobase() {}
  DaoChapter(const MYSQL* conn) : Daobase(conn) {}

  int getChapterList(const articleInfo::ArticleInfo& article, chapterInfo::ChapterInfo* chapterList);
  int getChapterByTime(const std::string& lastupdate, const int max, chapterInfo::ChapterInfo* chapterList);
  void getChapterMaxID(std::string& maxId);
    unsigned int getChapterMaxID();

  void addChapter(const chapterInfo::ChapterInfo &chapter);
  void addChapterCache(const chapterInfo::ChapterInfo& chapter);
  void updateChapterType(const chapterInfo::ChapterInfo& chapter);
  bool confirmCacheTran();
  void restCache() { m_sql = ""; }

private:
  void fillChapter(const MYSQL_ROW& row, chapterInfo::ChapterInfo& chapter);
  int traverseResult(const MYSQL_RES* res, chapterInfo::ChapterInfo* chapterList);

private:
  std::string m_sql;
};

#endif // NP_DAOCHAPTER_H
